import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';

enum Api {
  page = "/auth-service/extLdp/page",
  list = "/auth-service/extLdp/list",
  save = "/auth-service/extLdp/save",
  edit = "/auth-service/extLdp/update",
  get = "/auth-service/extLdp/get",
  delete = "/auth-service/extLdp/delete",
  deleteBatch = "/auth-service/extLdp/deleteBatch",
  exportXls = '/auth-service/extLdp/exportExcel',
  importExcel = '/auth-service/extLdp/importExcel',
}

export const getExportUrl = Api.exportXls;

export const getImportUrl = Api.importExcel;

export const pageLdp = (params) => {
  return defHttp.get({ url: Api.page, params });
}
export const listLdpTemplate = (params) => {
  return defHttp.get({ url: Api.page, params });
}


export const saveOrUpdateLdp = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
}


export const getLdpTmpl = (params) => {
  return defHttp.get({ url: Api.get, params });
}


export const deleteLdp = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

export const batchDeleteLdp = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}
